package com.haruhinav.controller;

import com.haruhinav.Utils.JWTUtils;
import com.haruhinav.entity.Note;
import com.haruhinav.entity.vo.ResultVO;
import com.haruhinav.mapper.NoteMapper;
import com.haruhinav.service.NoteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/api/note")
public class NoteController {

    @Autowired
    private NoteService noteService;
//  完整...
    @GetMapping("/a/query")
    public ResultVO findNoteByUId(@RequestParam("uid") Integer userId,HttpServletRequest request){

        return noteService.findNoteByUId(userId,false,JWTUtils.fromTokenGetUid(request));
    }
//    不查询内容
    @GetMapping("/a/query/nocontent")
    public  ResultVO findNoteByUIdNoContent(@RequestParam("uid") Integer userId,HttpServletRequest request){
        return noteService.findNoteByUId(userId,true,JWTUtils.fromTokenGetUid(request));
    }
    @PostMapping("/a/query/one")
    public ResultVO findNoteById(@RequestBody Note note, HttpServletRequest request){

        return noteService.findOneById(note, JWTUtils.fromTokenGetUid(request));
    }

    @PostMapping("/a/update")
    public ResultVO updateNoteById(@RequestBody Note note, HttpServletRequest request){
        return noteService.updateNoteById(note,JWTUtils.fromTokenGetUid(request));
    }
//    删除
    @PostMapping("/a/delete")
    public ResultVO delNoteById(@RequestBody Note note, HttpServletRequest request){
        return noteService.delNoteById(note,JWTUtils.fromTokenGetUid(request));
    }
//    添加
    @PostMapping("/a/add")
    public ResultVO addNote(@RequestBody Note note){
        return noteService.addNote(note);
    }
}
